﻿using System;
using OutlookContactsSync.Domain.Properties;
using OutlookContactsSync.Domain.Views;

namespace OutlookContactsSync
{
    public partial class StatusForm : BaseForm, IOutlookSyncStatusView   
    {
        public StatusForm()
        {
            InitializeComponent();
            InitializeControls();            
        }

        private void InitializeControls()
        {
            Text = Resources.StatusFormTitle;

            AmountOfUsersSynced = Resources.AmountOfContactsSynced + Settings.Default.LastSyncNewUsersAdded;

            AmountOfUsersRemoved = Resources.AmountOfContactsRemoved + Settings.Default.LastSyncUsersRemoved;

            AmountOfUsersUpdated = Resources.AmountOfContactsUpdated + Settings.Default.LastSyncUsersUpdated;

            LastSuccesFullSyncDate = (string.IsNullOrEmpty(Settings.Default.LastSyncDateTime))
                                            ? Resources.NoSuccesFullSync
                                            : Resources.LastSuccesfullSync + Settings.Default.LastSyncDateTime;

            LastSuccesfullSyncDuration = (Settings.Default.LastSyncTimeSpan.Seconds == 0)
                                            ? Resources.NoSuccesFullSync
                                            : Resources.LastSyncTook + Convert.ToInt32(Settings.Default.LastSyncTimeSpan.TotalSeconds) + " " + Resources.Seconds;

            ApplicationStatuslabel.Text = Resources.ApplicationStatus;
        }

        #region IOutlookSyncStatusView Members

        public string AmountOfUsersSynced
        {
            set
            {
                labelNewUsersLabel.Text = value;
            }
        }

        public string AmountOfUsersUpdated
        {
            set
            {
                labelUsersUpdated.Text = value;
            }
        }

        public string AmountOfUsersRemoved
        {
            set
            {
                labelUsersRemoved.Text = value;
            }
        }

        public string LastSuccesFullSyncDate
        {
            set
            {
                LastSuccesfullSynclabel.Text = value;
            }
        }

        public string LastSuccesfullSyncDuration
        {
            set
            {
                DurationOfLastSynclabel.Text = value;
            }
        }

        public override void ShowForm()
        {
            ShowDialog();
        }

        #endregion

        private void OkButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}